<?php
// +----------------------------------------------------------------------
// | RXThinkCMF_EVTP5.1_PRO前后端分离旗舰版框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2018~2021 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | 作者: ZhangXuanNeng <rxthinkcmf@163.com>
// +----------------------------------------------------------------------
// | 免责声明:
// | 本软件框架禁止任何单位和个人用于任何违法、侵害他人合法利益等恶意的行为，禁止用于任何违
// | 反我国法律法规的一切平台研发，任何单位和个人使用本软件框架用于产品研发而产生的任何意外
// | 、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带
// | 或衍生的损失等)，本团队不承担任何法律责任。本软件框架只能用于公司和个人内部的法律所允
// | 许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\BoxReportFacilityRemainService;
use app\admin\service\BoxReportMemberRemainService;
use app\admin\service\BoxReportMemberOverviewService;
use app\common\controller\Export;
use Exception;

class BoxStatisticsReport extends Backend
{
    /**
     * @Notes:数据总览
     * @Interface overviewList
     */
    public function overviewList()
    {
        $this->service = new BoxReportMemberOverviewService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * Desc : overviewEdit,数据修改
     * User : Steven
     * Date : 2024-07-03 13:56
     */
    public function overviewEdit()
    {
        $this->service = new BoxReportMemberOverviewService();
        $result        = $this->service->edit();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出数据总览
     * @Interface overviewExport
     */
    public function overviewExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }

        if (isset($param['platform']) && !empty($param['platform'])) {
            $map[] = ['platform', '=', $param['platform']];
        }
        $Export = new Export();
        $Export->overviewExport($param, $map);
    }


    /**
     * @Notes:盒子用户留存
     * @Interface overviewList
     */
    public function memberRemainList()
    {
        $this->service = new BoxReportMemberRemainService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出盒子用户留存
     * @Interface overviewExport
     */
    public function memberRemainExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }

        if (isset($param['platform']) && !empty($param['platform'])) {
            $map[] = ['platform', '=', $param['platform']];
        }
        $Export = new Export();
        $Export->memberRemainExport($map);
    }

    /**
     * @Notes:设备留存
     * @Interface overviewList
     */
    public function facilityRemainList()
    {
        $this->service = new BoxReportFacilityRemainService();
        $result        = $this->service->getList();
        return $this->jsonReturn($result);
    }

    /**
     * @Notes:导出设备留存
     * @Interface overviewExport
     */
    public function facilityRemainExport()
    {
        $param = request()->param();

        $map = [];

        if (!empty($param['time_range'])) {
            $param['time_range'][0] = implode('', explode('-', $param['time_range'][0]));
            $param['time_range'][1] = implode('', explode('-', $param['time_range'][1]));
            $map[]                  = ['day_time', '>=', $param['time_range'][0]];
            $map[]                  = ['day_time', '<=', $param['time_range'][1]];
        }

        if (isset($param['platform']) && !empty($param['platform'])) {
            $map[] = ['platform', '=', $param['platform']];
        }
        $Export = new Export();
        $Export->facilityRemainExport($map);
    }


}
